﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WFBSYS.Entity;
using System.Data.OleDb;
using System.Collections;

namespace WFBSYS.Model
{
    class TsCustomDB : DBEntity
    {
        public ArrayList selectAll()
        {
            ArrayList list = new ArrayList();

            OleDbDataReader aReader = this.getDataReader("select * from ts_custom");
            try
            {
                while (aReader.Read())
                {
                    TsCustom tc = new TsCustom();
                    tc.CustomId = aReader.GetInt32(0);
                    tc.CustomType = aReader.GetInt32(1);
                    tc.CustomName = aReader.GetString(2);
                    tc.CustomPerson = aReader.GetString(3);
                    tc.CustomPhone = aReader.GetString(4);
                    tc.CustomAddress = aReader.GetString(5);
                    tc.CustomPs = aReader.GetString(6);
                    tc.CustomTotal = aReader.GetFloat(7);
                    list.Add(tc);
                }
            }
            catch (Exception e) {
                Console.WriteLine(e.Message);
            }
            this.closeDataReader();
            
            return list;
        }

        public void save(TsCustom custom) {
            OleDbParameter[] parameters = new OleDbParameter[7];
            parameters[0] = new OleDbParameter("@custom_type", OleDbType.Integer);
            parameters[0].Value = custom.CustomType;
            parameters[1] = new OleDbParameter("@custom_name", OleDbType.BSTR);
            parameters[1].Value = custom.CustomName;
            parameters[2] = new OleDbParameter("@custom_person", OleDbType.BSTR);
            parameters[2].Value = custom.CustomPerson;
            parameters[3] = new OleDbParameter("@custom_phone", OleDbType.BSTR);
            parameters[3].Value = custom.CustomPhone;
            parameters[4] = new OleDbParameter("@custom_address", OleDbType.BSTR);
            parameters[4].Value = custom.CustomAddress;
            parameters[5] = new OleDbParameter("@custom_ps", OleDbType.BSTR);
            parameters[5].Value = custom.CustomPs;
            parameters[6] = new OleDbParameter("@custom_total", OleDbType.Decimal);
            parameters[6].Value = custom.CustomTotal;
            this.sqlWrite("insert into ts_custom (custom_type, custom_name, custom_person, custom_phone, custom_address, custom_ps, custom_total) values (@custom_type, @custom_name, @custom_person, @custom_phone, @custom_address, @custom_ps, @custom_total)", parameters);
        }

    }
}
